package com.atguigu.srb.base.controller;

import com.atguigu.srb.base.mapper.DictMapper;
import com.atguigu.srb.base.model.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Classname RedisTestController
 * @Date 2022/11/21 13:49
 * @Created by 16342
 * @Author wangchengshan
 */
@RestController
@RequestMapping("redis")
public class RedisTestController {

    @Resource
    private DictMapper dictMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("test")
    public String test() {
        Dict dict = new Dict();
        dict.setId(1L);
        dict.setCreateTime(new Date());
        //向数据库中存储string类型的键值对, 过期时间5分钟
        redisTemplate.opsForValue().set("dict", dict, 5, TimeUnit.MINUTES);
        System.out.println(redisTemplate.opsForValue().get("dict"));
        System.out.println((Dict)redisTemplate.opsForValue().get("dict"));
        return "ok";
    }
}
